package com.yalemang.photovalut

import UserManager
import android.app.Activity
import android.app.Application
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.LiveData
import com.google.android.gms.ads.MobileAds
import com.yalemang.framework.cache.AppKeyValueImpl
import com.yalemang.framework.utils.AppSwitchListener
import com.yalemang.photovalut.base.encryption.EncryptionManager
import com.yalemang.photovalut.base.sql.SQLManager
import com.yalemang.photovalut.ui.calculator.CalculatorActivity

class App : Application() {

    companion object{
        lateinit var app: App
    }

    override fun onCreate() {
        super.onCreate()

        app = this
        AppKeyValueImpl.init(this)
        UserManager.instance.init()
        EncryptionManager.getInstance().init(this)
        MobileAds.initialize(this){
            Log.d("xing","初始化SDK")
        }
        SQLManager.getInstance().init(this)

        registerActivityLifecycleCallbacks(object : AppSwitchListener(){
            override fun switch(isBackstage: Boolean, activity: Activity) {
                if (!isBackstage) {
                    goTOCalculator(activity)
                }
            }
        })
    }

    private fun goTOCalculator(activity: Activity) {
        val intent = Intent(activity, CalculatorActivity::class.java)
        activity.startActivity(intent)
    }
}